<?php
include_once "common.php";
$db = new PDO('mysql:host=localhost', 'root', '12qwas');
$db->exec('create database if not exists db2');//不存在就创建数据库
$db->exec('use db2');//使用数据库
$db->exec('create table if not exists students(xh varchar(10) not null primary key, name varchar(50),
age int)');//不存在就创建表
$r=$db->exec('delete from students where age>=20');
p("成功删除 $r 条记录");
$db->exec('truncate table students');//删除表中的所有数据
$r=$db->exec("insert into students values('213110601','张三',20),('213110602','李四',22),('213110603
','王五',18)");
p("成功插入 $r 条记录");

$db = new PDO('mysql:host=127.0.0.1; dbname=db2', 'root', '12qwas');
$ps = $db->query('select * from students',PDO::FETCH_ASSOC); // PDO::FETCH_NUM
table($ps);

